<template>
    <div>
   <el-row class="goods-list-title"><h1>所有申请记录查看</h1> </el-row>
      <!-- <el-card class="card-search">
      <el-form inline>
        <el-form-item label="活动名字:"><el-input v-model="goodNameSearch"></el-input></el-form-item>
        <el-form-item>
          <el-button type="primary" round icon="Search" @click="goodSearchBtn">查询</el-button>
          <el-button round type="primary" icon="Refresh" @click="goodNameSearch=''" >重置</el-button>
        </el-form-item>
      </el-form>
    </el-card> -->
     <el-card>

          <el-table
        :data="tableData"
        style="width: 100%"
        :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }"
        v-loading="loading"
      >
        <el-table-column prop="activityName" label="活动名字" />
        <el-table-column prop="status" label="当前活动状态" />
        <el-table-column prop="userName" label="申请用户" />
        <el-table-column prop="createTime" label="申请时间" />
        <el-table-column label="详情内容"> 
          <template #default="props">
            <el-button size="small" type="primary" @click="getDetailBtn(props.row)">活动详情</el-button>
          </template>
        </el-table-column>
        </el-table>
         <el-row class="el-row-center">
          <el-pagination
        :page-size="pageSize"
        layout="total, prev, pager, next"
        :total="total"
        @current-change="handleCurrentChange"
      ></el-pagination>
         </el-row>
       <el-dialog v-model="activityContentDialogVisible" title="活动内容"  >
      <el-table :data="Activitycontent" :show-header="false"  style="width: 100%" >
        <el-table-column  prop="label"></el-table-column>
        <el-table-column >
           <template #default="prop">
             <span> {{detailContentData[prop.row.value]}} </span>
           </template>
        </el-table-column>
      </el-table>
    </el-dialog>
     </el-card>
</div>
    
</template>
<script lang="ts">
import { defineComponent ,reactive,ref, toRefs,onMounted} from 'vue'
import { ApiGetActivityDetail, ApiGetAllBookRecord ,ApiGoodsDetail,ApiGoodsSearch, ApiRecordSearch} from "@/api/index";
export default defineComponent({
  name:'ApplyList',
  setup(){
     let pageInfo = reactive<IGPageInfo>({
      pageNum: 1,
      total: 2,
      pages: 2,
      pageSize: 15,
    });
    const Activitycontent = [
       { label: "活动名称", value: "activityName" },
       { label: "活动规则", value: "activityRule" },
        { label: "活动详情", value: "activityDetail" },
      { label: "活动结束时间", value: "activityEndTime" },
      { label: "当前产品名字", value: "goodName" },
      { label: "产品详情", value: "goodDetail" },
      { label: "产品价格", value: "goodPrice" },
      { label: "产品使用手册介绍", value: "manual" },
      { label: "客户须知", value: "notice" },
      { label: "产品限购量", value: "limitNum" },
    ];
    let goodNameSearch = ref("")
    let loading = ref<boolean>(false)
      let tableData = ref<Array<any>>([]);
     const getRecords = async ()=>{
       loading.value = true
    const {data:res} = await ApiGetAllBookRecord(pageInfo.pageNum) as Record<string,any>
      tableData.value = res.list;
      pageInfo.total = res.total;
      pageInfo.pages = res.pages;
      pageInfo.pageSize = res.pageSize
      loading.value = false
     
     
         
     }
     let detailContentData = ref()
     let activityContentDialogVisible = ref<boolean>(false)
      const  getDetailBtn = async (info)=>{
       let activityId = info.activityId
    
       loading.value = true
      const {data:activityRes} = await ApiGetActivityDetail(activityId) as Record<string,any>
      
      const {data:goodres} = await ApiGoodsDetail(activityRes.goodId) as Record<string,any>
    
     detailContentData.value = {...activityRes,...goodres}
     loading.value = false
     activityContentDialogVisible.value = true
   }

     const goodSearchBtn = async ()=>{
       const {data:res} = await ApiRecordSearch(goodNameSearch.value) as Record<string,any>
        tableData.value = res.list;
       pageInfo.total = res.total;
       pageInfo.pages = res.pages;
       
     }
     const handleCurrentChange = (val: number) => {
      pageInfo.pageNum = val;
      getRecords();
    };
    onMounted(()=>{
      getRecords()
    })
    return{
       ...toRefs(pageInfo),
       tableData,
       handleCurrentChange,
       loading,
       goodNameSearch,
       goodSearchBtn,
       getDetailBtn,
       activityContentDialogVisible,
       detailContentData,
       Activitycontent
    }
  }
})
</script>
<style lang="less" scoped>
.goods-list-title {
  display: flex;
  justify-content: center;
  h1 {
    color: rgb(109, 135, 221);
    font-size: 20px;
  }
}
</style>